package com.cdxy.service.impl;

import com.cdxy.dmr.dataObject.SceneDO;
import com.cdxy.dmr.dataObject.ScenePostDO;
import com.cdxy.dmr.repository.ScenePostRepository;
import com.cdxy.dmr.repository.SceneRepository;
import com.cdxy.model.dto.req.ScenePostReleaseReq;
import com.cdxy.service.IScenePostService;
import com.cdxy.util.BeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * <p>
 * 用户景点发帖表 服务实现类
 * </p>
 *
 * @author autoGenCode
 * @since 2020-03-05
 */
@Service
public class ScenePostServiceImpl implements IScenePostService {

    @Autowired
    private ScenePostRepository scenePostRepository;

    @Autowired
    private SceneRepository sceneRepository;

    @Override
    public void scenePostRelease(ScenePostReleaseReq scenePostReleaseReq) {
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日");
        Integer sceneId = scenePostReleaseReq.getSceneId();
        ScenePostDO scenePostDO = BeanUtil.copyPropertiesByFastJson(scenePostReleaseReq, ScenePostDO.class);
        scenePostDO.setViewTime(dateTimeFormatter.format(LocalDateTime.now()));
        SceneDO sceneDO = sceneRepository.getById(sceneId);
        scenePostDO.setSceneImg(sceneDO.getSmallImg());
        scenePostDO.setSceneName(sceneDO.getName());
        scenePostRepository.save(scenePostDO);
    }
}
